|
|
@@ -127,24 +127,24 @@ You can request structured JSON output from the model by specifying an `outputFo
|
|
|
const result = await client.session.prompt({
|
|
|
path: { id: sessionId },
|
|
|
body: {
|
|
|
- parts: [{ type: 'text', text: 'Research Anthropic and provide company info' }],
|
|
|
+ parts: [{ type: "text", text: "Research Anthropic and provide company info" }],
|
|
|
outputFormat: {
|
|
|
- type: 'json_schema',
|
|
|
+ type: "json_schema",
|
|
|
schema: {
|
|
|
- type: 'object',
|
|
|
+ type: "object",
|
|
|
properties: {
|
|
|
- company: { type: 'string', description: 'Company name' },
|
|
|
- founded: { type: 'number', description: 'Year founded' },
|
|
|
+ company: { type: "string", description: "Company name" },
|
|
|
+ founded: { type: "number", description: "Year founded" },
|
|
|
products: {
|
|
|
- type: 'array',
|
|
|
- items: { type: 'string' },
|
|
|
- description: 'Main products'
|
|
|
- }
|
|
|
+ type: "array",
|
|
|
+ items: { type: "string" },
|
|
|
+ description: "Main products",
|
|
|
+ },
|
|
|
},
|
|
|
- required: ['company', 'founded']
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ required: ["company", "founded"],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
// Access the structured output
|
|
|
@@ -154,29 +154,29 @@ console.log(result.data.info.structured_output)
|
|
|
|
|
|
### Output Format Types
|
|
|
|
|
|
-| Type | Description |
|
|
|
-|------|-------------|
|
|
|
-| `text` | Default. Standard text response (no structured output) |
|
|
|
-| `json_schema` | Returns validated JSON matching the provided schema |
|
|
|
+| Type | Description |
|
|
|
+| ------------- | ------------------------------------------------------ |
|
|
|
+| `text` | Default. Standard text response (no structured output) |
|
|
|
+| `json_schema` | Returns validated JSON matching the provided schema |
|
|
|
|
|
|
### JSON Schema Format
|
|
|
|
|
|
When using `type: 'json_schema'`, provide:
|
|
|
|
|
|
-| Field | Type | Description |
|
|
|
-|-------|------|-------------|
|
|
|
-| `type` | `'json_schema'` | Required. Specifies JSON schema mode |
|
|
|
-| `schema` | `object` | Required. JSON Schema object defining the output structure |
|
|
|
-| `retryCount` | `number` | Optional. Number of validation retries (default: 2) |
|
|
|
+| Field | Type | Description |
|
|
|
+| ------------ | --------------- | ---------------------------------------------------------- |
|
|
|
+| `type` | `'json_schema'` | Required. Specifies JSON schema mode |
|
|
|
+| `schema` | `object` | Required. JSON Schema object defining the output structure |
|
|
|
+| `retryCount` | `number` | Optional. Number of validation retries (default: 2) |
|
|
|
|
|
|
### Error Handling
|
|
|
|
|
|
If the model fails to produce valid structured output after all retries, the response will include a `StructuredOutputError`:
|
|
|
|
|
|
```typescript
|
|
|
-if (result.data.info.error?.name === 'StructuredOutputError') {
|
|
|
- console.error('Failed to produce structured output:', result.data.info.error.message)
|
|
|
- console.error('Attempts:', result.data.info.error.retries)
|
|
|
+if (result.data.info.error?.name === "StructuredOutputError") {
|
|
|
+ console.error("Failed to produce structured output:", result.data.info.error.message)
|
|
|
+ console.error("Attempts:", result.data.info.error.retries)
|
|
|
}
|
|
|
```
|
|
|
|
|
|
@@ -298,27 +298,27 @@ const { providers, default: defaults } = await client.config.providers()
|
|
|
|
|
|
### Sessions
|
|
|
|
|
|
-| Method | Description | Notes |
|
|
|
-| ---------------------------------------------------------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
|
-| `session.list()` | List sessions | Returns <a href={typesUrl}><code>Session[]</code></a> |
|
|
|
-| `session.get({ path })` | Get session | Returns <a href={typesUrl}><code>Session</code></a> |
|
|
|
-| `session.children({ path })` | List child sessions | Returns <a href={typesUrl}><code>Session[]</code></a> |
|
|
|
-| `session.create({ body })` | Create session | Returns <a href={typesUrl}><code>Session</code></a> |
|
|
|
-| `session.delete({ path })` | Delete session | Returns `boolean` |
|
|
|
-| `session.update({ path, body })` | Update session properties | Returns <a href={typesUrl}><code>Session</code></a> |
|
|
|
-| `session.init({ path, body })` | Analyze app and create `AGENTS.md` | Returns `boolean` |
|
|
|
-| `session.abort({ path })` | Abort a running session | Returns `boolean` |
|
|
|
-| `session.share({ path })` | Share session | Returns <a href={typesUrl}><code>Session</code></a> |
|
|
|
-| `session.unshare({ path })` | Unshare session | Returns <a href={typesUrl}><code>Session</code></a> |
|
|
|
-| `session.summarize({ path, body })` | Summarize session | Returns `boolean` |
|
|
|
-| `session.messages({ path })` | List messages in a session | Returns `{ info: `<a href={typesUrl}><code>Message</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}[]` |
|
|
|
-| `session.message({ path })` | Get message details | Returns `{ info: `<a href={typesUrl}><code>Message</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}` |
|
|
|
+| Method | Description | Notes |
|
|
|
+| ---------------------------------------------------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
|
+| `session.list()` | List sessions | Returns <a href={typesUrl}><code>Session[]</code></a> |
|
|
|
+| `session.get({ path })` | Get session | Returns <a href={typesUrl}><code>Session</code></a> |
|
|
|
+| `session.children({ path })` | List child sessions | Returns <a href={typesUrl}><code>Session[]</code></a> |
|
|
|
+| `session.create({ body })` | Create session | Returns <a href={typesUrl}><code>Session</code></a> |
|
|
|
+| `session.delete({ path })` | Delete session | Returns `boolean` |
|
|
|
+| `session.update({ path, body })` | Update session properties | Returns <a href={typesUrl}><code>Session</code></a> |
|
|
|
+| `session.init({ path, body })` | Analyze app and create `AGENTS.md` | Returns `boolean` |
|
|
|
+| `session.abort({ path })` | Abort a running session | Returns `boolean` |
|
|
|
+| `session.share({ path })` | Share session | Returns <a href={typesUrl}><code>Session</code></a> |
|
|
|
+| `session.unshare({ path })` | Unshare session | Returns <a href={typesUrl}><code>Session</code></a> |
|
|
|
+| `session.summarize({ path, body })` | Summarize session | Returns `boolean` |
|
|
|
+| `session.messages({ path })` | List messages in a session | Returns `{ info: `<a href={typesUrl}><code>Message</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}[]` |
|
|
|
+| `session.message({ path })` | Get message details | Returns `{ info: `<a href={typesUrl}><code>Message</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}` |
|
|
|
| `session.prompt({ path, body })` | Send prompt message | `body.noReply: true` returns UserMessage (context only). Default returns <a href={typesUrl}><code>AssistantMessage</code></a> with AI response. Supports `body.outputFormat` for [structured output](#structured-output) |
|
|
|
-| `session.command({ path, body })` | Send command to session | Returns `{ info: `<a href={typesUrl}><code>AssistantMessage</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}` |
|
|
|
-| `session.shell({ path, body })` | Run a shell command | Returns <a href={typesUrl}><code>AssistantMessage</code></a> |
|
|
|
-| `session.revert({ path, body })` | Revert a message | Returns <a href={typesUrl}><code>Session</code></a> |
|
|
|
-| `session.unrevert({ path })` | Restore reverted messages | Returns <a href={typesUrl}><code>Session</code></a> |
|
|
|
-| `postSessionByIdPermissionsByPermissionId({ path, body })` | Respond to a permission request | Returns `boolean` |
|
|
|
+| `session.command({ path, body })` | Send command to session | Returns `{ info: `<a href={typesUrl}><code>AssistantMessage</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}` |
|
|
|
+| `session.shell({ path, body })` | Run a shell command | Returns <a href={typesUrl}><code>AssistantMessage</code></a> |
|
|
|
+| `session.revert({ path, body })` | Revert a message | Returns <a href={typesUrl}><code>Session</code></a> |
|
|
|
+| `session.unrevert({ path })` | Restore reverted messages | Returns <a href={typesUrl}><code>Session</code></a> |
|
|
|
+| `postSessionByIdPermissionsByPermissionId({ path, body })` | Respond to a permission request | Returns `boolean` |
|
|
|
|
|
|
---
|
|
|
|